package com.example.disruptor.demo.disruptor;

import com.lmax.disruptor.EventTranslator;
import lombok.extern.slf4j.Slf4j;

/**
 * 事件转换
 * Created by liunanhua on 2018/7/19.
 */
@Slf4j
public class LongEventTranslator2 implements EventTranslator<LongEvent> {

    @Override
    public void translateTo(LongEvent longEvent, long sequence) {
        this.generateData(longEvent);
    }

    private LongEvent generateData(LongEvent longEvent) {
        long val = (long)(Math.random() * 10000.0d);
        longEvent.setValue(val); // 随机生成一个数
        log.info("Thread Id " + Thread.currentThread().getId() + " 写完一个event");
        return longEvent;
    }


}
